//
//  MainTabBar.swift
//  TakeTime
//
//  Created by bachelor on 16/10/23.
//  Copyright © 2016年 bachelor. All rights reserved.
//

import UIKit

class MainTabBar: UITabBar {

    /*
    // Only override draw() if you perform custom drawing.
    // An empty implementation adversely affects performance during animation.
    override func draw(_ rect: CGRect) {
        // Drawing code
    }
    */
    override func layoutSubviews() {
        super.layoutSubviews()
        
        let w = self.bounds.width / 5
        let h = self.bounds.height
        let rect = CGRect(x: 0, y: 0, width: w, height: h)
        var index: CGFloat = 0
        
        for v in subviews {
            
            
            if v is UIControl && !(v is UIButton)  {
                v.frame = rect
                v.frame.origin.x += (index * w)
                
                index += (index == 1 ? 2 : 1)
            }
        }
        composeButton.frame = CGRect(x: 2 * w, y: 0, width: w, height: h)
    }
    lazy var composeButton: UIButton = { [unowned self] in
        let btn = UIButton()
        btn.setImage(UIImage(named: "tabbar_compose_icon_add"), for: .normal)
        btn.setImage(UIImage(named: "tabbar_compose_icon_add_highlighted"), for: .highlighted)
        btn.setBackgroundImage(UIImage(named: "tabbar_compose_button"), for: .normal)
        btn.setBackgroundImage(UIImage(named: "tabbar_compose_button_highlighted"), for: .highlighted)
        self.addSubview(btn)
        return btn
    }()
}
